'use strict'
const path = require('path');
const http = require('http');
const fs = require('fs');

const hostname = '127.0.0.1';
const port = 3000

const server = http.createServer((req, res) => {
    const fileName = path.basename(req.url);
    const filePath = path.join(__dirname, fileName);

    // res.statusCode = 200;
    res.setHeader = ('Content-Type', 'text/plain');

    if (fs.existsSync(filePath)) {
        fs.readFile(filePath, 'utf-8', (err, data) => {
            res.end(data + '\n');
        })
    } else {
        res.end('Not Found');
    }
    // res.end('Hello\n');
})

server.listen(port, hostname, () => {
    console.log(`server running at http://${hostname}:${port}`);
})